$(function() {
	validationOption = {
		rules : {
			old : {
				required : true
			},
			newp : {
				required : true
			},
			repeat : {
				required : true,
				equalTo : "#newp"
			}
		},
		highlight : function(element) {
			$(element).closest('.form-group').addClass('has-error');
		},
		unhighlight : function(element) {
			$(element).closest('.form-group').removeClass('has-error');
		},
		errorElement : 'span',
		errorClass : 'help-block',
		errorPlacement : function(error, element) {
			if (element.parent('.input-group').length) {
				error.insertAfter(element.parent());
			} else {
				error.insertAfter(element);
			}
		},
		nsubmit : false,
		onfocusout : true
	};
	var validator = $('#changeForm').validate(validationOption);

	$("#change").on(
			"click",
			function() {
				if (validator.valid()) {
					$.ajax({
						url : window.basePath + "user/changepassword",
						type : 'POST',
						data : {
							old : $("#old").val(),
							newp : $("#newp").val()
						},
						success : function(data) {
							if (data == "success") {
								$("#alert-success").append("Password Changed!")
										.removeClass("hidden").hide().fadeIn(
												"slow");
								$("#alert-success").fadeOut(5000);
							} else if (data == "error") {
								$("#alert-warning").append("Error Password!!")
										.removeClass("hidden").hide().fadeIn(
												"slow");
								$("#alert-warning").fadeOut(5000);
							}
						}

					});
				}

			});
});